home *** CD-ROM | disk | FTP | other *** search
- /**
- --
- -- App: QuickDraw GX Shell
- --
- -- Version: 1.0 1/93: added general QuickDraw GX support & scrolling
- -- 1.1 4/93: added support for QuickDraw GX printing and testing to
- -- see is QuickDraw GX is installed.
- --
- -- File: QuickDraw GX Shell - print.c
- --
- -- Comments: This files contains all of the calls required to print the contents of
- -- the window. We support all of the QuickDraw GX file menu print commands
- -- except - "By Page Setup...". Also, we only support one page of output,
- -- because the contents of the window will fit into one page.
- --
- --
- -- Components: QuickDraw GX Shell (main).c
- -- QuickDraw GX Shell (main).h
- -- QuickDraw GX Shell - print.c
- -- QuickDraw GX Shell - print.h
- -- QuickDraw GX Shell - scroll.c
- -- QuickDraw GX Shell - scroll.h
- -- QuickDraw GX Shell (main).π.rsrc
- --
- --
- -- Notes: 1) Print this file in landscape for the best results
- -- 2) If you are using THINK C v5.x, I have added markers to navigate the
- -- code.
- -- 3) This code was adapted from teh "Banana Jr." sample.
- -- 4) This file uses the "Exceptions.h" library to catch errors as
- -- described in the "Living In An Exceptional World" article published
- -- in the August 1992 issue of develop.
- --
- --
- -- Author: Pete "Luke" Alexander
- -- Developer Technical Support
- -- AppleLink: DEVSUPPORT
- --
- --
- -- ©1993 Apple Computer, Inc.
- --
- **/
-
- #include <ToolUtils.h>
- #include <Traps.h>
-
- #include "PrintingManager.h"
- #include "graphics routines.h"
-
- #include "Exceptions.h"
-
-
- #include "QuickDraw GX Shell (main).h"
-
- extern gxShape gthePage;
- extern gxViewPort gcontentViewPort;
- extern gxJob gDocumentJob;
- extern Boolean gQDGXPrintingInstalled;
-
- gxEditMenuRecord gEditMenu;
-
-
-
- /**----- PrintInit ---------------------------------------------------------------------------
- --
- -- This function initializes the QuickDraw GX printing system.
- --
- **/
- gxJob PrintInit()
- {
- gxJob documentJob;
- OSErr printErr;
-
- gEditMenu.editMenuID = mEdit;
- gEditMenu.cutItem = iCut;
- gEditMenu.copyItem = iCopy;
- gEditMenu.pasteItem = iPaste;
- gEditMenu.clearItem = iClear;
- gEditMenu.undoItem = iUndo;
-
- //
- // We intialize the QuickDraw GX printing system after we have created our
- // graphics client and a gxJob.
- //
- nrequire(GXInitPrinting (), InitPrintingFailed);
-
- nrequire(printErr = GXNewJob(&documentJob), NewJobFailed);
-
- return (documentJob);
-
-
- InitPrintingFailed:
- DebugStr ("\p Initializing GX Print Land - FAILED!! (PrintInit) ");
-
- NewJobFailed:
- DebugStr ("\p NewJob - FAILED!! (PrintInit) ");
- }
-
-
-
-
- /**----- TermintatePrintLand -----------------------------------------------------------------
- --
- -- When the user quits the application, this function is called to clean up the QuickDraw
- -- GX printing system. We also dispose of the job we created above.
- --
- **/
- void TermintatePrintLand(gxJob documentJob)
- {
-
- if (gQDGXPrintingInstalled)
- {
- //
- // Dispose of the gxJob we created earlier.
- //
- nrequire(GXDisposeJob(documentJob), DisposeJobFailed);
-
- //
- // Close up the QuickDraw GX printing system, before we dispose of the
- // client.
- nrequire( GXExitPrinting (), ExitPrintingFailed);
-
- return;
-
- DisposeJobFailed:
- DebugStr ("\p DisposeJob - FAILED!! (TermintatePrintLand) ");
-
- ExitPrintingFailed:
- DebugStr ("\p ExitPrinting - FAILED!! (TermintatePrintLand) ");
- }
- }
-
-
-
- /**----- DoPrintOneCopy ------------------------------------------------------------------------
- --
- -- This function supports the "Print One Copy" command from the File menu.
- --
- **/
- void DoPrintOneCopy (WindowPtr window, gxJob documentJob, gxShape thePage)
- {
- Str255 windowTitle;
- OSErr printError;
-
- if (window) {
-
- GetWTitle(window, windowTitle);
-
- //
- // Start sending the job to a spool file. The job will be titled the same as
- // our window, and it contains 1 page.The name will be displayed in the status dialogs.
- //
- GXStartJob(documentJob, windowTitle, 1);
-
- //
- // Send the entire page down to the printer. We can send the entire
- // job because all of the shapes that are being printed have been
- // collected into "thePage", therefore the Print Manager does not
- // need to do any work.
- //
-
- GXPrintPage(documentJob, 1, GXGetJobFormat(documentJob, 1), thePage);
- //
- // This calls tells the Print Manager that we have finished sending the spool
- // file, therefore terminate the transmission (i.e. the connection to the
- // printer.
- //
- GXFinishJob(documentJob);
-
-
- if (GXGetJobError(documentJob) != noErr) DebugStr ("\pGetJobError - FAILED!!! (DoPrintOneCopyCommand) ");
- } else DebugStr ("\p Bad window!! (DoPrintOneCopyCommand) ");
-
- }
-
-
-
- /**----- DoDocumentSetupCommand ----------------------------------------------------------------
- --
- -- This function supports the "Document Setup" command from the File menu.
- --
- **/
- void DoDocumentSetupCommand(gxJob documentJob)
- {
- OSErr printError;
- gxDialogResult result;
-
- //
- // Display the docuemnt format dialog. This dialog gives the user the ability
- // to reformat the entire print job to use the same format, such as landscape printing.
- //
- result = GXJobDefaultFormatDialog(documentJob, &gEditMenu);
-
- if (GXGetJobError(gDocumentJob) != noErr)
- DebugStr ("\p JobFormatDialog - FAILED!!! (JobFormatDialog) ");
- }
-
-
-
-
- /**----- DoPrintCommand ------------------------------------------------------------------------
- --
- -- This function supports the "Print..." command from the File menu.
- --
- **/
-
- void DoPrintCommand(WindowPtr window, gxJob documentJob, gxShape thePage)
- {
- OSErr printError;
-
- if (window)
- {
- //
- // Display the print dialog to the user, the user has the ability at this point to
- // specify the pages to print, the number of copies, and save the print job as
- // a Portable Digital Docuemnt or a PostScript file (if you are currently printing to
- // a PostScript printer).
- //
- // In the case of this application, we only have one page of shapes to print.
- //
- if (GXJobPrintDialog(documentJob, &gEditMenu) == gxOkSelected) {
- printError = GXGetJobError(documentJob);
-
- if (!(printError))
- DoPrintOneCopy(window, documentJob, thePage);
- }
- } else DebugStr ("\p Bad window!! (DoPrintCommand) ");
- }
-
-